package org.fly.controller.admin;

import org.fly.bean.CustomerLevel;
import org.fly.bean.query.CustomerLevelQuery;
import org.fly.controller.AbstractController;
import org.fly.service.CustomerLevelService;
import org.fly.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* Created by autoCode on 2018-01-31 20:25:40.
*/
@Controller
@RequestMapping("/admin/customerLevel/")
public class AdminCustomerLevelController extends AbstractController {

    @Autowired
    CustomerLevelService customerLevelService;

    @RequestMapping(value = "list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public String list(CustomerLevelQuery query){
        List<CustomerLevel> list =  customerLevelService.list(query);
        return toJSONString(createDataTip(list));
    }
    @RequestMapping(value = "count", produces = "application/json;charset=utf-8")
    @ResponseBody
    public String count(CustomerLevelQuery query){
        long count =  customerLevelService.count(query);
        long pageCount = PageUtils.getPage(count,query.getSize());
        return toJSONString(createDataTip(pageCount));
    }
    @RequestMapping(value = "find",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String find(String id){
        CustomerLevel bean = customerLevelService.findById(id);
        return toJSONString(createDataTip(bean));
    }

    @RequestMapping(value = "save", produces = "application/json;charset=utf-8")
    @ResponseBody
    public String save(CustomerLevel bean, HttpServletRequest request){
        try {
            customerLevelService.save(bean);
            return toJSONString(SUCCESS);
        } catch (Exception e) {
        e.printStackTrace();
        return toExceptionString(e);
        }
    }

}